]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
cleanup: Use Array.includes() to check for element existence
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 14 Jul 2018 20:56:22 +0000 (22:56 +0200)
committerFlorian Müllner <florian.muellner@gmail.com>
Mon, 1 Jul 2019 21:28:52 +0000 (21:28 +0000)
We can use that newer method where we don't care about the actual position
of an element inside the array.

(Array.includes() and Array.indexOf() do behave differently in edge cases,
for example in the handling of NaN, but those don't matter to us)

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/152

29 files changed:
js/extensionPrefs/main.js
js/misc/extensionUtils.js
js/misc/keyboardManager.js
js/ui/appDisplay.js
js/ui/calendar.js
js/ui/components/__init__.js
js/ui/components/autorunManager.js
js/ui/components/networkAgent.js
js/ui/components/polkitAgent.js
js/ui/dash.js
js/ui/endSessionDialog.js
js/ui/extensionDownloader.js
js/ui/extensionSystem.js
js/ui/grabHelper.js
js/ui/inhibitShortcutsDialog.js
js/ui/keyboard.js
js/ui/main.js
js/ui/messageList.js
js/ui/messageTray.js
js/ui/padOsd.js
js/ui/panel.js
js/ui/remoteSearch.js
js/ui/runDialog.js
js/ui/sessionMode.js
js/ui/status/network.js
js/ui/status/volume.js
js/ui/windowManager.js
js/ui/workspace.js
js/ui/workspaceThumbnail.js

index 43efa95e92976e0f2741450e3376ff4c7cb7077b..24ecdc165db0a723fe3515bdcfcfd78f5111b95c 100644 (file)
@@ -582,12 +582,12 @@ class ExtensionRow extends Gtk.ListBoxRow {
 
     _isEnabled() {
         let extensions = this._settings.get_strv('enabled-extensions');
-        return extensions.indexOf(this.uuid) != -1;
+        return extensions.includes(this.uuid);
     }
 
     _enable() {
         let extensions = this._settings.get_strv('enabled-extensions');
-        if (extensions.indexOf(this.uuid) != -1)
+        if (extensions.includes(this.uuid))
             return;
 
         extensions.push(this.uuid);
index cf308b31f141f0f339b0c3a7c489313e0f714219..89a085d68a768637f576399017e9c01f2f07063c 100644 (file)
@@ -31,7 +31,7 @@ function getCurrentExtension() {
     // Search for an occurrence of an extension stack frame
     // Start at 1 because 0 is the stack frame of this function
     for (let i = 1; i < stack.length; i++) {
-        if (stack[i].indexOf('/gnome-shell/extensions/') > -1) {
+        if (stack[i].includes('/gnome-shell/extensions/')) {
             extensionStackLine = stack[i];
             break;
         }
index 99e100231a2f0136fde0279fe467eddc71d9e0b0..ae71b646e18a30c61f037b53469b2f282210e68a 100644 (file)
@@ -125,7 +125,7 @@ var KeyboardManager = class {
 
     _getLocaleLayout() {
         let locale = GLib.get_language_names()[0];
-        if (locale.indexOf('_') == -1)
+        if (!locale.includes('_'))
             locale = DEFAULT_LOCALE;
 
         let [found, , id] = GnomeDesktop.get_input_source_from_locale(locale);
index ea86c81b9ace54a153e8a013978d14a8e018d064..00019772a0edda4ce598e33536c7c3c3438a0d6a 100644 (file)
@@ -69,7 +69,7 @@ function _getCategories(info) {
 
 function _listsIntersect(a, b) {
     for (let itemA of a)
-        if (b.indexOf(itemA) >= 0)
+        if (b.includes(itemA))
             return true;
     return false;
 }
@@ -1165,7 +1165,7 @@ var FolderIcon = class FolderIcon {
         let excludedApps = this._folder.get_strv('excluded-apps');
         let appSys = Shell.AppSystem.get_default();
         let addAppId = appId => {
-            if (excludedApps.indexOf(appId) >= 0)
+            if (excludedApps.includes(appId))
                 return;
 
             let app = appSys.lookup_app(appId);
@@ -1728,7 +1728,7 @@ var AppIconMenu = class AppIconMenu extends PopupMenu.PopupMenu {
             let appInfo = this._source.app.get_app_info();
             let actions = appInfo.list_actions();
             if (this._source.app.can_open_new_window() &&
-                actions.indexOf('new-window') == -1) {
+                actions.includes('new-window')) {
                 this._newWindowMenuItem = this._appendMenuItem(_("New Window"));
                 this._newWindowMenuItem.connect('activate', () => {
                     if (this._source.app.state == Shell.AppState.STOPPED)
@@ -1742,7 +1742,7 @@ var AppIconMenu = class AppIconMenu extends PopupMenu.PopupMenu {
 
             if (discreteGpuAvailable &&
                 this._source.app.state == Shell.AppState.STOPPED &&
-                actions.indexOf('activate-discrete-gpu') == -1) {
+                actions.includes('activate-discrete-gpu')) {
                 this._onDiscreteGpuMenuItem = this._appendMenuItem(_("Launch using Dedicated Graphics Card"));
                 this._onDiscreteGpuMenuItem.connect('activate', () => {
                     if (this._source.app.state == Shell.AppState.STOPPED)
index cd3e879c4e3391b6217139eb2749ac73e7fe4679..d7c5bc80543b15962aa74336e81459bc0e6d592c 100644 (file)
@@ -38,7 +38,7 @@ function isToday(date) {
 function _isWorkDay(date) {
     /* Translators: Enter 0-6 (Sunday-Saturday) for non-work days. Examples: "0" (Sunday) "6" (Saturday) "06" (Sunday and Saturday). */
     let days = C_('calendar-no-work', "06");
-    return days.indexOf(date.getDay().toString()) == -1;
+    return !days.includes(date.getDay().toString());
 }
 
 function _getBeginningOfDay(date) {
index 6d6cc9d69441efbf28f0f83ae6902d3b0c648720..652f6951c1e697d48f470df112e78f1bc0c9843f 100644 (file)
@@ -13,13 +13,13 @@ var ComponentManager = class {
         let newEnabledComponents = Main.sessionMode.components;
 
         newEnabledComponents.filter(
-            name => this._enabledComponents.indexOf(name) == -1
+            name => !this._enabledComponents.includes(name)
         ).forEach(name => {
             this._enableComponent(name);
         });
 
         this._enabledComponents.filter(
-            name => newEnabledComponents.indexOf(name) == -1
+            name => !newEnabledComponents.includes(name)
         ).forEach(name => {
             this._disableComponent(name);
         });
index 34c7d62509c33a9f8654a04dd1905c113dceee13..4891e5d953698c649ef50416f6ebe63eea17584e 100644 (file)
@@ -40,7 +40,7 @@ function isMountRootHidden(root) {
     let path = root.get_path();
 
     // skip any mounts in hidden directory hierarchies
-    return (path.indexOf('/.') != -1);
+    return (path.includes('/.'));
 }
 
 function isMountNonLocal(mount) {
@@ -192,15 +192,15 @@ var AutorunDispatcher = class {
 
     _getAutorunSettingForType(contentType) {
         let runApp = this._settings.get_strv(SETTING_START_APP);
-        if (runApp.indexOf(contentType) != -1)
+        if (runApp.includes(contentType))
             return AutorunSetting.RUN;
 
         let ignore = this._settings.get_strv(SETTING_IGNORE);
-        if (ignore.indexOf(contentType) != -1)
+        if (ignore.includes(contentType))
             return AutorunSetting.IGNORE;
 
         let openFiles = this._settings.get_strv(SETTING_OPEN_FOLDER);
-        if (openFiles.indexOf(contentType) != -1)
+        if (openFiles.includes(contentType))
             return AutorunSetting.FILES;
 
         return AutorunSetting.ASK;
index 48bbd308f552f89f5faecade32c2788e10ebcb35..dca8318ede62b452d40713b711da03bc0ef2d7b8 100644 (file)
@@ -327,7 +327,7 @@ class NetworkSecretDialog extends ModalDialog.ModalDialog {
             this._getPPPoESecrets(content.secrets);
             break;
         case 'gsm':
-            if (this._hints.indexOf('pin') != -1) {
+            if (this._hints.includes('pin')) {
                 let gsmSetting = this._connection.get_setting_gsm();
                 content.title = _("PIN code required");
                 content.message = _("PIN code is needed for the mobile broadband device");
@@ -695,7 +695,7 @@ var NetworkAgent = class {
             body = _("A password is required to connect to “%s”.".format(connection.get_id()));
             break;
         case 'gsm':
-            if (hints.indexOf('pin') != -1) {
+            if (hints.includes('pin')) {
                 let gsmSetting = connection.get_setting_gsm();
                 title = _("PIN code required");
                 body = _("PIN code is needed for the mobile broadband device");
index 27566531fa4b01b6ab2b5b9afa84cddf8a2f9fb2..a44165df97b262eb172a61c5ce7c4a01b5003e9f 100644 (file)
@@ -45,9 +45,9 @@ var AuthenticationDialog = GObject.registerClass({
         }
 
         let userName = GLib.get_user_name();
-        if (userNames.indexOf(userName) < 0)
+        if (!userNames.includes(userName))
             userName = 'root';
-        if (userNames.indexOf(userName) < 0)
+        if (!userNames.includes(userName))
             userName = userNames[0];
 
         this._user = AccountsService.UserManager.get_default().get_user(userName);
index 0032c912ea73f96e6571bc1c26fb5914d0dc1ade..878045410479668d0c3f6969462afbf35acf8573 100644 (file)
@@ -700,14 +700,14 @@ var Dash = class Dash {
             }
 
             // App removed at oldIndex
-            if (oldApp && newApps.indexOf(oldApp) == -1) {
+            if (oldApp && !newApps.includes(oldApp)) {
                 removedActors.push(children[oldIndex]);
                 oldIndex++;
                 continue;
             }
 
             // App added at newIndex
-            if (newApp && oldApps.indexOf(newApp) == -1) {
+            if (newApp && !oldApps.includes(newApp)) {
                 addedItems.push({ app: newApp,
                                   item: this._createAppItem(newApp),
                                   pos: newIndex });
index d83578fb950caaf6420f47070ce1640dda5bd6f8..3c7729eb3cfe681660b8de7653d0e2b312ae8191 100644 (file)
@@ -585,7 +585,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
     }
 
     _onInhibitorLoaded(inhibitor) {
-        if (this._applications.indexOf(inhibitor) < 0) {
+        if (!this._applications.includes(inhibitor)) {
             // Stale inhibitor
             return;
         }
index 184db2464de77d6916f1873214034cdb9741233f..fb36ac4788b44ae25be8db7932cdb5c108c66668 100644 (file)
@@ -228,7 +228,7 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
         function callback() {
             // Add extension to 'enabled-extensions' for the user, always...
             let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY);
-            if (enabledExtensions.indexOf(uuid) == -1) {
+            if (!enabledExtensions.includes(uuid)) {
                 enabledExtensions.push(uuid);
                 global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
             }
index 6244c39b44fe50d43c3ea9cbd77476182801c5fd..744f5e7ac193cd84a3b6e1b87a6fd4eae234794b 100644 (file)
@@ -169,7 +169,7 @@ function loadExtension(extension) {
     if (checkVersion && ExtensionUtils.isOutOfDate(extension)) {
         extension.state = ExtensionState.OUT_OF_DATE;
     } else {
-        let enabled = enabledExtensions.indexOf(extension.uuid) != -1;
+        let enabled = enabledExtensions.includes(extension.uuid);
         if (enabled) {
             if (!initExtension(extension.uuid))
                 return;
index 50991501906edd0ddbb46bd92ba643eb940173bc..39873e16fb39045de852158b1a80897c6a360ebe 100644 (file)
@@ -87,7 +87,7 @@ var GrabHelper = class GrabHelper {
     _isWithinGrabbedActor(actor) {
         let currentActor = this.currentGrab.actor;
         while (actor) {
-            if (this._actors.indexOf(actor) != -1)
+            if (this._actors.includes(actor))
                 return true;
             if (actor == currentActor)
                 return true;
index 170cd1a33938d0f2453fc8fd8dce431f88b780e7..6c988577c540293f08be5d6bb15d61c0cbab8a8a 100644 (file)
@@ -111,7 +111,7 @@ var InhibitShortcutsDialog = GObject.registerClass({
     }
 
     vfunc_show() {
-        if (this._app && APP_WHITELIST.indexOf(this._app.get_id()) != -1) {
+        if (this._app && APP_WHITELIST.includes(this._app.get_id())) {
             this._emitResponse(DialogResponse.ALLOW);
             return;
         }
index b6a26663ac689fe6d68745276ccc63c6a9433538..c30f90a76ec4f7c87b098968f4e71dcfb0acc30a 100644 (file)
@@ -1074,7 +1074,7 @@ var Keyboard = class Keyboard {
                 let manager = Clutter.DeviceManager.get_default();
                 let device = manager.get_device(deviceId);
 
-                if (device.get_device_name().indexOf('XTEST') < 0) {
+                if (!device.get_device_name().includes('XTEST')) {
                     this._lastDeviceId = deviceId;
                     this._syncEnabled();
                 }
index 04f333ea14e289dbef7016972d75a8db85a95ccd..9b69860010798545a9004ba5de20fa5dd25b5c3a 100644 (file)
@@ -663,7 +663,7 @@ function initializeDeferredWork(actor, callback, props) {
     _deferredWorkData[workId] = { 'actor': actor,
                                   'callback': callback };
     actor.connect('notify::mapped', () => {
-        if (!(actor.mapped && _deferredWorkQueue.indexOf(workId) >= 0))
+        if (!(actor.mapped && _deferredWorkQueue.includes(workId)))
             return;
         _queueBeforeRedraw(workId);
     });
@@ -693,7 +693,7 @@ function queueDeferredWork(workId) {
         logError(new Error(message), message);
         return;
     }
-    if (_deferredWorkQueue.indexOf(workId) < 0)
+    if (!_deferredWorkQueue.includes(workId))
         _deferredWorkQueue.push(workId);
     if (data.actor.mapped) {
         _queueBeforeRedraw(workId);
index bd97ffcb0481f1bbff2d67b365beb224131b6045..93c3fc3ac7a285b60539065c9febfed979263660 100644 (file)
@@ -72,7 +72,7 @@ var URLHighlighter = class URLHighlighter {
             let urlId = this._findUrlAtPos(event);
             if (urlId != -1) {
                 let url = this._urls[urlId].url;
-                if (url.indexOf(':') == -1)
+                if (!url.includes(':'))
                     url = 'http://' + url;
 
                 Gio.app_info_launch_default_for_uri(url, global.create_app_launch_context(0, -1));
index f1f79d8c2bd9a49b7234301888f72f12b1c248d4..4007f1b00ba244b011d1ca5849813a71cb59273f 100644 (file)
@@ -228,7 +228,7 @@ class NotificationApplicationPolicy extends NotificationPolicy {
         this._settings.set_string('application-id', this.id + '.desktop');
 
         let apps = this._masterSettings.get_strv('application-children');
-        if (apps.indexOf(this._canonicalId) < 0) {
+        if (!apps.includes(this._canonicalId)) {
             apps.push(this._canonicalId);
             this._masterSettings.set_strv('application-children', apps);
         }
@@ -772,7 +772,7 @@ var Source = class Source {
     }
 
     pushNotification(notification) {
-        if (this.notifications.indexOf(notification) >= 0)
+        if (this.notifications.includes(notification))
             return;
 
         while (this.notifications.length >= MAX_NOTIFICATIONS_PER_SOURCE)
@@ -1069,7 +1069,7 @@ var MessageTray = class MessageTray {
             // If a new notification is updated while it is being hidden,
             // we stop hiding it and show it again.
             this._updateShowingNotification();
-        } else if (this._notificationQueue.indexOf(notification) < 0) {
+        } else if (!this._notificationQueue.includes(notification)) {
             // If the queue is "full", we skip banner mode and just show a small
             // indicator in the panel; however do make an exception for CRITICAL
             // notifications, as only banner mode allows expansion.
index a4af4729741da93e4bdbbfef358fd7f2146d5d43..903b967c46f1b8c9811de603cb53a960c7cff2f1 100644 (file)
@@ -630,7 +630,7 @@ var PadOsd = class {
             // If the device is being removed, destroy the padOsd.
             if (device == this.padDevice) {
                 this.destroy();
-            } else if (this._groupPads.indexOf(device) != -1) {
+            } else if (this._groupPads.includes(device)) {
                 // Or update the pad chooser if the device belongs to
                 // the same group.
                 this._groupPads.splice(this._groupPads.indexOf(device), 1);
@@ -749,8 +749,7 @@ var PadOsd = class {
     }
 
     _requestForOtherPad(pad) {
-        if (pad == this.padDevice ||
-            this._groupPads.indexOf(pad) == -1)
+        if (pad == this.padDevice || !this._groupPads.includes(pad))
             return;
 
         let editionMode = this._editionMode;
@@ -801,7 +800,7 @@ var PadOsd = class {
 
         // If the event comes from another pad in the same group,
         // show the OSD for it.
-        if (this._groupPads.indexOf(event.get_source_device()) != -1) {
+        if (this._groupPads.includes(event.get_source_device())) {
             this._requestForOtherPad(event.get_source_device());
             return Clutter.EVENT_STOP;
         }
index be02785a8cf2c20e224166f0ff5610faa04fc714..fbd65a2636dc673bfeee48b8982d85a6b89be21f 100644 (file)
@@ -1056,9 +1056,9 @@ class Panel extends St.Widget {
         this._updateBox(panel.center, this._centerBox);
         this._updateBox(panel.right, this._rightBox);
 
-        if (panel.left.indexOf('dateMenu') != -1)
+        if (panel.left.includes('dateMenu'))
             Main.messageTray.bannerAlignment = Clutter.ActorAlign.START;
-        else if (panel.right.indexOf('dateMenu') != -1)
+        else if (panel.right.includes('dateMenu'))
             Main.messageTray.bannerAlignment = Clutter.ActorAlign.END;
         // Default to center if there is no dateMenu
         else
index ce8c4d09bc098e44fe775ab37a721207a52d5acc..ae6c6dab778636d915e30dfb7834b4bd3a2fed25 100644 (file)
@@ -146,10 +146,10 @@ function loadRemoteSearchProviders(searchSettings, callback) {
 
         if (provider.defaultEnabled) {
             let disabled = searchSettings.get_strv('disabled');
-            return disabled.indexOf(appId) == -1;
+            return !disabled.includes(appId);
         } else {
             let enabled = searchSettings.get_strv('enabled');
-            return enabled.indexOf(appId) != -1;
+            return enabled.includes(appId);
         }
     });
 
index 9186ff7bb670aa1a746c49c39eeb6da2d63e5778..21bd04c3eca5b38ccc5ce1185e20ec78f85ec0c6 100644 (file)
@@ -182,7 +182,7 @@ class RunDialog extends ModalDialog.ModalDialog {
     }
 
     _getCompletion(text) {
-        if (text.indexOf('/') != -1) {
+        if (text.includes('/')) {
             return this._pathCompleter.get_completion_suffix(text);
         } else {
             return this._getCommandCompletion(text);
index ae6c64dd39c0762230e64b94758da6abf012a9b6..70a6e8a15c0da7d38c74947601d948082f4daae8 100644 (file)
@@ -128,7 +128,7 @@ function _loadMode(file, info) {
     let propBlacklist = ['unlockDialog'];
     for (let prop in _modes[DEFAULT_MODE]) {
         if (newMode[prop] !== undefined &&
-            propBlacklist.indexOf(prop) == -1)
+            !propBlacklist.includes(prop))
             _modes[modeName][prop] = newMode[prop];
     }
     _modes[modeName]['isPrimary'] = true;
index 7c2499d0eda69830f65d148cb4798e5ffaf854ad..8ad451347e306d3df67e20291c8f1001048275ed 100644 (file)
@@ -1040,7 +1040,7 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
     _checkConnections(network, accessPoint) {
         this._connections.forEach(connection => {
             if (accessPoint.connection_valid(connection) &&
-                network.connections.indexOf(connection) == -1) {
+                !network.connections.includes(connection)) {
                 network.connections.push(connection);
             }
         });
@@ -1059,7 +1059,7 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
 
         if (pos != -1) {
             network = this._networks[pos];
-            if (network.accessPoints.indexOf(accessPoint) != -1) {
+            if (network.accessPoints.includes(accessPoint)) {
                 log('Access point was already seen, not adding again');
                 return;
             }
index ae2497a93955077743c8490a9ce6e82cd481aaa8..cc270500b4658f748230aa5480c272238dadb1e5 100644 (file)
@@ -215,7 +215,7 @@ var OutputStreamSlider = class extends StreamSlider {
         // of different identifiers for headphones, and I could
         // not find the complete list
         if (sink.get_ports().length > 0)
-            return sink.get_port().port.indexOf('headphone') >= 0;
+            return sink.get_port().port.includes('headphone');
 
         return false;
     }
index 19dc263cd975e422b21092c37b0a57a297c6eb71..d016f33716ecab8037c1b633f8b8378e2d5b1dda 100644 (file)
@@ -1288,7 +1288,7 @@ var WindowManager = class {
             return false;
 
         let type = actor.meta_window.get_window_type();
-        return types.indexOf(type) >= 0;
+        return types.includes(type);
     }
 
     _removeEffect(list, actor) {
@@ -1501,7 +1501,7 @@ var WindowManager = class {
     _sizeChangedWindow(shellwm, actor) {
         if (!actor.__animationInfo)
             return;
-        if (this._resizing.indexOf(actor) != -1)
+        if (this._resizing.includes(actor))
             return;
 
         let actorClone = actor.__animationInfo.clone;
index 50ac141d995615df676283659f18deb55704b9de..1b6c63eb39200ed46ebd97a5241c0bff59565c9f 100644 (file)
@@ -536,7 +536,7 @@ var WindowOverlay = class {
         let [cloneX, cloneY, cloneWidth, cloneHeight] = this._windowClone.slot;
 
         let layout = Meta.prefs_get_button_layout();
-        let side = layout.left_buttons.indexOf(Meta.ButtonFunction.CLOSE) > -1 ? St.Side.LEFT : St.Side.RIGHT;
+        let side = layout.left_buttons.includes(Meta.ButtonFunction.CLOSE) ? St.Side.LEFT : St.Side.RIGHT;
 
         let buttonX;
         let buttonY = cloneY - (button.height - button._overlap);
index 969167178951733d2d17b51359d7afbf86436051..be196c04bca1a2b43548ce13e034b4557a8f02ce 100644 (file)
@@ -378,7 +378,7 @@ var WorkspaceThumbnail = class {
             return;
         }
 
-        if (this._allWindows.indexOf(metaWin) == -1) {
+        if (!this._allWindows.includes(metaWin)) {
             let minimizedChangedId = metaWin.connect('notify::minimized',
                                                      this._updateMinimized.bind(this));
             this._allWindows.push(metaWin);